<template>
  <div class="recommend-container">
    <div class="recommend-header">
      <h2>今日推荐</h2>
    </div>
    
    <el-row :gutter="20">
      <el-col :span="24" v-for="section in recommendSections" :key="section.title">
        <div class="section-title">
          <h3>{{ section.title }}</h3>
          <p class="section-desc">{{ section.description }}</p>
        </div>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="12" :md="8" :lg="6" v-for="dish in section.dishes" :key="dish.id">
            <el-card :body-style="{ padding: '0px' }" class="dish-card">
              <div class="dish-image-container">
                <img :src="dish.image" class="dish-image">
                <div class="category-tag">{{ dish.category }}</div>
              </div>
              <div style="padding: 14px;">
                <h3>{{ dish.name }}</h3>
                <p class="dish-description">{{ dish.description }}</p>
                <div class="bottom">
                  <span class="price">¥{{ dish.price }}</span>
                  <el-button 
                    type="primary" 
                    size="small" 
                    @click="addToCart(dish)"
                    :loading="addingToCart === dish.id"
                  >
                    <i class="el-icon-shopping-cart-2"></i>
                    加入购物车
                  </el-button>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'DishRecommend',
  data() {
    return {
      addingToCart: null,
      recommendSections: [
        {
          title: '本周热门',
          description: '最受欢迎的美味佳肴',
          dishes: this.$store.state.recommendDishes.hotDishes
        },
        {
          title: '新品上市',
          description: '崭新推出的特色菜品',
          dishes: this.$store.state.recommendDishes.newDishes
        },
        {
          title: '厨师推荐',
          description: '大厨精心推荐的招牌菜',
          dishes: this.$store.state.recommendDishes.chefDishes
        }
      ]
    }
  },
  methods: {
    addToCart(dish) {
      this.addingToCart = dish.id
      this.$store.commit('addToCart', dish)
      setTimeout(() => {
        this.$message({
          message: '已添加到购物车',
          type: 'success',
          duration: 2000
        })
        this.addingToCart = null
      }, 300)
    }
  }
}
</script>

<style scoped>
.recommend-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}
.recommend-header {
  margin-bottom: 30px;
}
.recommend-header h2 {
  font-size: 24px;
  color: #303133;
  margin: 0;
}
.section-title {
  margin: 30px 0 20px;
}
.section-title h3 {
  font-size: 20px;
  color: #303133;
  margin: 0;
}
.section-desc {
  color: #909399;
  margin: 8px 0 0;
}
.dish-card {
  margin-bottom: 20px;
  transition: all 0.3s;
  border: none;
  border-radius: 8px;
  overflow: hidden;
}
.dish-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.1);
}
.dish-image-container {
  height: 200px;
  overflow: hidden;
  position: relative;
}
.dish-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  transition: transform 0.3s;
}
.dish-card:hover .dish-image {
  transform: scale(1.05);
}
.category-tag {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
}
.dish-description {
  color: #666;
  margin: 10px 0;
  height: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 13px;
}
.price {
  font-size: 18px;
  color: #f56c6c;
  font-weight: bold;
}
.el-button {
  border-radius: 20px;
  padding: 8px 20px;
}
.el-button i {
  margin-right: 5px;
}
</style> 